package com.hc.java.sync;

/**
 * @author cdhuangchao3
 * @date 2023/12/2 6:32 PM
 */
public class 线程同步 {

    static  Boolean flag = false;

    public static void main(String[] args) {
        new Thread(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("flag=false-"+System.currentTimeMillis());
            flag = true;
            System.out.println("flag=true-"+System.currentTimeMillis());
        }, "t1").start();
        new Thread(() -> {
            int i = 0;
            while (!flag) {
                i++;
                System.out.println(i+"-"+System.currentTimeMillis());
            }
            System.out.println("stop..."+System.currentTimeMillis());
        }, "t2").start();
    }
}
